from joblib import load
import numpy as np

class ClassificationModel(object):
    def __init__(self):
        self.knn = load('svc.joblib')
        self.scaler = load('scaler.joblib')
        self.label_encoder = load('label_encoder.joblib')

    def get_predictor_category(self, new_data):
        feature_order = ['eps', 'total_revenue_ps', 'undist_profit_ps', 'gross_margin', 'fcff', 'fcfe', 'tangible_asset', 'bps', 'grossprofit_margin', 'npta']
        new_values = np.array([new_data[feature] for feature in feature_order])
        new_values_scaled = self.scaler.transform(new_values.reshape(1, -1))
        predicted_label = self.knn.predict(new_values_scaled)
        predicted_category = self.label_encoder.inverse_transform(predicted_label)
        return predicted_category[0]

if __name__ == '__main__':
    cl = ClassificationModel()
    new_data = {
        'eps': -4.17,
        'total_revenue_ps': 28.7641,
        'undist_profit_ps': 3.6995,
        'gross_margin': 390116000000,
        'fcff': 13682000000,
        'fcfe': 13361900000,
        'tangible_asset': 13679000000,
        'bps': 16.987,
        'grossprofit_margin': 16.1731,
        'npta': -3.4899
    }
    predicted_category = cl.get_predictor_category(new_data)
    print(f"预测分类: {predicted_category}")
